@extends('layouts.main')

@inject('special_offer','App\Http\Presenters\ChoicePresenter')

@section('title', '编辑物料')

@section('content')
<h3>@yield('title')</h3>
<div class="btn-group" role="group">
  	<a href="{{ action('BusinessData\MaterialController@index') }}" class="btn btn-primary">返回列表</a>
</div>

<form class="form-horizontal" method="post" action="{{ action('BusinessData\MaterialController@update', $model) }}">
    @csrf
    @method('PUT')

    <div class="form-group">
		<label for="year" class="col-sm-2 control-label">年度</label>
		<div class="col-sm-6">
			<select class="form-control" id="year" name="year">
				@for($i = 2020; $i <= 2030; $i++)
				<option value="{{ $i }}" @if(old('year') == $i || $model->year == $i) selected @endif>{{ $i }}</option>
				@endfor
			</select>
			@if($errors->first('year'))
			<p class="help-block error">{{ $errors->first('year') }}</p>
			@endif
		</div>
    </div>

    <div class="form-group">
		<label for="material" class="col-sm-2 control-label">物料编码</label>
		<div class="col-sm-3">
			<input class="form-control" id="material" name="material" placeholder="请输入物料编码" value="{{ old('material', $model->material) }}">
			@if($errors->first('material'))
			<p class="help-block error">{{ $errors->first('material') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="material_desc" class="col-sm-2 control-label">物料描述</label>
		<div class="col-sm-3">
		  <input class="form-control" id="material_desc" name="material_desc" placeholder="请输入物料描述" value="{{ old('material_desc', $model->material_desc) }}">
		  @if($errors->first('material_desc'))
		  <p class="help-block error">{{ $errors->first('material_desc') }}</p>
		  @endif
		</div>
	</div>

	<div class="form-group">
		<label for="category_small_id" class="col-sm-2 control-label">统计用细分类</label>
		<div class="col-sm-6">
			<select class="form-control" id="category_small_id" name="category_small_id">
				<option value="0">请选择统计用细分类</option>
				@foreach($category_smalls as $category_small)
				<option value="{{ $category_small->id }}" @if(old('category_small_id') == $category_small->id || $model->category_small_id == $category_small->id) selected @endif>{{ $category_small->name }}</option>
				@endforeach
			</select>
			@if($errors->first('category_small_id'))
			<p class="help-block error">{{ $errors->first('category_small_id') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="category_big_id" class="col-sm-2 control-label">大分类</label>
		<div class="col-sm-6">
			<select class="form-control" id="category_big_id" name="category_big_id">
				<option value="0">请选择大分类</option>
				@foreach($category_bigs as $category_big)
				<option value="{{ $category_big->id }}" @if(old('category_big_id') == $category_big->id || $model->category_big_id == $category_big->id) selected @endif>{{ $category_big->name }}</option>
				@endforeach
			</select>
			@if($errors->first('category_big_id'))
			<p class="help-block error">{{ $errors->first('category_big_id') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="category_contract_id" class="col-sm-2 control-label">合同大类</label>
		<div class="col-sm-6">
			<select class="form-control" id="category_contract_id" name="category_contract_id">
				<option value="0">请选择合同大类</option>
				@foreach($category_contracts as $category_contract)
				<option value="{{ $category_contract->id }}" @if(old('category_contract_id') == $category_contract->id || $model->category_contract_id == $category_contract->id) selected @endif>{{ $category_contract->name }}</option>
				@endforeach
			</select>
			@if($errors->first('category_contract_id'))
			<p class="help-block error">{{ $errors->first('category_contract_id') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="category_key_product_id" class="col-sm-2 control-label">重点产品分类</label>
		<div class="col-sm-6">
			<select class="form-control" id="category_key_product_id" name="category_key_product_id">
				<option value="0">请选择重点产品分类</option>
				@foreach($category_key_products as $category_key_product)
				<option value="{{ $category_key_product->id }}" @if(old('category_key_product_id') == $category_key_product->id || $model->category_key_product_id == $category_key_product->id) selected @endif>{{ $category_key_product->name }}</option>
				@endforeach
			</select>
			@if($errors->first('category_key_product_id'))
			<p class="help-block error">{{ $errors->first('category_key_product_id') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="is_special_offer" class="col-sm-2 control-label">是否特价</label>
		<div class="col-sm-6">
			<select class="form-control" id="is_special_offer" name="is_special_offer">
				@foreach(config('report.special_offer') as $value)
				<option value="{{ $value }}" @if(old('is_special_offer', $model->is_special_offer) == $value) selected @endif>{{ $special_offer->judgeWhether($value) }}</option>
				@endforeach
			</select>
			@if($errors->first('is_special_offer'))
			<p class="help-block error">{{ $errors->first('is_special_offer') }}</p>
			@endif
		</div>
    </div>

    <div class="form-group">
		<div class="col-sm-offset-2 col-sm-10">
			<button type="submit" class="btn btn-primary">提交</button>
		</div>
    </div>
</form>

@endsection